home *** CD-ROM | disk | FTP | other *** search
/ 130 MIDI Tool Box / 130 MIDI Tool Box.iso / dac12x16 / 16to12.c next >
C/C++ Source or Header  |  1988-05-20  |  501b  |  22 lines

  1. /* 16to12--float to short for 12-bit DAC
  2.  * 16to12 < infile > outfile
  3.  */
  4. #include <stdio.h>
  5. #include <fcntl.h>
  6. #include <io.h>
  7. #define  DAC12 2047 /* 2^12 / 2 - 1 */
  8. #define  DAC16 32767 /* 2^16 / 2 - 1 */
  9.  
  10. main()
  11. {
  12.     short x;
  13.     short y;
  14.     setmode(fileno(stdin), O_BINARY);
  15.     setmode(fileno(stdout), O_BINARY);
  16.  
  17.     while (fread((char *)&x, sizeof(short), 1, stdin))
  18.     {     y = (float)x / DAC16 * DAC12;
  19.           fwrite((char *)&y, sizeof(short), 1, stdout);
  20.     }
  21. }
  22.